<?php
/*********************************************
  CPG Dragonfly™ CMS
  ********************************************
  Copyright © 2004 - 2005 by CPG-Nuke Dev Team
  http://www.dragonflycms.com

  Dragonfly is released under the terms and conditions
  of the GNU GPL version 2 or any later version
**********************************************/
if (!defined('ADMIN_MOD_INSTALL')) { exit; }

class Statistics  extends Installer_Module {

	public
		$radmin,
		$version,
		$modname,
		$description,
		$author,
		$website,
		$dbtables;

	public function __construct() {
		$this->radmin = false;
		$this->version = '2.0';
		$this->modname = 'Statistics';
		$this->description = 'Keep track of who visits your site and at what time';
		$this->author = 'CPG-Nuke Dev Team';
		$this->website = 'dragonflycms.org';
		$this->dbtables = array('counter', 'stats_hour');
	}

	public function pre_install() { return true; }
	public function post_install() { return true; }
	public function pre_uninstall() { return true; }
	public function post_uninstall() { return true; }
	public function pre_upgrade($prev_version)
	{
		if ($prev_version < 2) {
			// Merge duplicate records
			global $db;
			$tbl = $db->TBL->counter;
			$qr = $db->query("SELECT type, var, SUM(count) as count FROM {$tbl} GROUP BY type, var");
			$data = array();
			while ($r = $qr->fetch_assoc()) { $data[] = $r; }
			$db->exec("DELETE FROM {$db->TBL->counter}");
			foreach ($data as $r) { $tbl->insert($r); }
		}
		return true;
	}
	public function post_upgrade($prev_version) { return true; }

}
